﻿<cfsilent>
	<cfscript>
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		sql = "	SELECT
					i.institute_id,i.institute_name
				FROM
					t_subject sbj
					INNER JOIN t_institute i ON sbj.institute_id = i.institute_id
				GROUP BY
					i.institute_id,i.institute_name
				ORDER BY
					i.institute_name";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_ins = queryObj.execute(sql = sql).getResult();
		
		sql = "	SELECT
					sbj.sbj_id,sbj.sbj_name,sbj.institute_id
				FROM
					t_subject sbj
				WHERE
					sbj.sbj_direction = '0'
				ORDER BY
					sbj.institute_id,sbj.level_code ASC,sbj.term_start ASC,sbj.sbj_name ASC";

		queryObj = new Query(datasource = application.dnsSlave);
		rs_sub = queryObj.execute(sql = sql).getResult();
		
		/*
		
		
		sql = "	SELECT
					DISTINCT a.grade
				FROM
					t_condition a
				WHERE
					EXISTS(
						SELECT 0 FROM t_schema b INNER JOIN t_subject sbj ON b.sbj_id = sbj.sbj_id
						WHERE a.grade = b.grade
						AND b.grade >= :currentYear  - sbj.schooling_length
					)
				ORDER BY
					a.grade DESC";
		
		
		*/
		

		sql = "	SELECT
					DISTINCT a.grade
				FROM
					t_condition a
				WHERE
					EXISTS(
						SELECT 0 FROM t_schema b INNER JOIN t_subject sbj ON b.sbj_id = sbj.sbj_id
						WHERE a.grade = b.grade
					)
				ORDER BY
					a.grade DESC";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "currentYear", value = year(now()), cfsqltype = "cf_sql_char");
		rs_edition = queryObj.execute(sql = sql).getResult();
		
		
		sql = "	SELECT
					i.institute_id,i.institute_name
				FROM
					t_subject a
					INNER JOIN t_institute i ON a.institute_id = i.institute_id
				WHERE
					EXISTS(
						SELECT 
							0 
						FROM 
							t_schema b
						WHERE
							a.sbj_id = b.sbj_id
					)
				GROUP BY
					i.institute_id,i.institute_name
				ORDER BY
					i.institute_name";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_sourceDep = queryObj.execute(sql = sql).getResult();
		

		sql = "	SELECT
					t.sign_id,
					tch.tch_name,
					t.grade,sbj.sbj_name,
					t.sign_reason,
					t.sign_status,
					t.date_created,t.date_valid
				FROM
					t_schema_modify t
					INNER JOIN t_teacher tch ON t.sign_user_id = tch.tch_id
					INNER JOIN t_subject sbj ON sbj.sbj_id = t.sbj_id
				WHERE
					t.sign_status = 'W'
				ORDER BY
					t.date_created DESC";
		queryObj = new Query(datasource = application.dnsSlave);
		rs_sign = queryObj.execute(sql = sql).getResult();

		

		event.setArg("pageTitle", "教学运行基础数据 - 培养方案");

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");

		targetArgs = structNew();

		if ( rs_sign.recordCount ) {
			currentTab = "labWaiting";
		} else if ( rs_edition.recordCount ) {
			currentTab = event.getArg("Edition", rs_edition['grade'][1]);
		} else {
			currentTab = "labCreate";
		}

		passArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('programCourse')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">课程库</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>培养方案
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
                        <cfloop query="rs_edition">
							<span <cfif currentTab eq rs_edition.grade>class="active"</cfif> id="labSchema<cfoutput>#rs_edition.grade#</cfoutput>" tabTarget="Schema<cfoutput>#rs_edition.grade#</cfoutput>"><cfoutput>#rs_edition.grade#</cfoutput>版</span>
						</cfloop>
						<span <cfif currentTab eq "labCreate">class="active"</cfif> id="labCreate" tabTarget="Create">设置新培养方案</span>
						<span <cfif currentTab eq "labCopy">class="active"</cfif> id="labCopy" tabTarget="Copy">复制培养方案</span>
						<span <cfif currentTab eq "labImport">class="active"</cfif> id="labImport" tabTarget="Import">导入培养方案数据</span>
						<cfif rs_sign.recordCount>
							<span <cfif currentTab eq "labWaiting">class="active"</cfif> id="labWaiting" tabTarget="Waiting">修订申请</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
                <cfloop query="rs_edition">
					<div id="Schema<cfoutput>#rs_edition.grade#</cfoutput>" class="tabContent">
						
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programSchemaEditionDownloadExcel', { Edition=rs_edition.grade })#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载培养方案</span></a>
							</div>
							<h3><cfoutput>#rs_edition.grade#</cfoutput>版 培养方案</h3>
							<p><span class="img icon16x16 message"></span>点击专业名称查看该专业培养方案计划课程开设信息</p>
						</div>
						
                        <cfset sql = "SELECT
											sbj.sbj_id, sbj.sbj_name
										FROM
											t_schema a
											INNER JOIN t_subject sbj ON a.sbj_id = sbj.sbj_id
										GROUP BY
											sbj.sbj_id,sbj.sbj_name
										ORDER BY
											sbj.sbj_name ASC" />
                                            
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam( name="grade", value=rs_edition.grade, cfsqltype="cf_sql_char")/>
                        <cfset rs_depSchema = queryObj.execute( sql=sql ).getResult() />
			

						<cfloop query="rs_depSchema">
							<div class="noticeBlock">
								<h3><cfoutput>#rs_depSchema.sbj_name#</cfoutput></h3>
								<hr/>
							</div>
							
                            <cfset sql = "	SELECT
												sbj.sbj_id,sbj.sbj_name,sbj.term_start,sbj.level_code
											FROM
												t_schema s
												INNER JOIN t_subject sbj ON s.sbj_id = sbj.sbj_id
											WHERE
												sbj.sbj_direction = '0'
											GROUP BY
												sbj.sbj_id,sbj.sbj_name,sbj.term_start,sbj.level_code
											ORDER BY
												sbj.sbj_name" />

                            <cfset queryObj = new Query(datasource = application.dnsSlave)/>
							<cfset queryObj.addParam(name = "grade", value = rs_edition.grade, cfsqltype = "cf_sql_char")/>
                            <cfset queryObj.addParam(name = "subjectId", value = rs_depSchema.sbj_id, cfsqltype = "cf_sql_varchar")/>
                            <cfset rs_subject = queryObj.execute(sql = sql).getResult() />
							
							<div class="clearfix">
								<div class="UICardTable">
                                    <cfloop query="rs_subject">
										<cfset structInsert(targetArgs, "Edition", rs_edition.grade, true) />
										<cfset structInsert(targetArgs, "SubID", rs_subject.sbj_id, true) />
										<cfset structInsert(targetArgs, "Schema", rs_edition.grade & rs_subject.sbj_id, true) />
										<dl>
											<dt>
												<a href="<cfoutput>#buildURL('programSchemaEditionBySubject', targetArgs)#</cfoutput>">
													<em class="subject"><!--imgholder--></em>
													<dd>
														<h3><cfoutput>#rs_subject.sbj_name#</cfoutput></h3>
														<div><cfoutput>#dictAdvice.getTermEnrol(rs_subject.term_start)#-#dictAdvice.getStudentLevel(rs_subject.level_code)#</cfoutput></div>
													</dd>
												</a>
											</dt>
										</dl>
									</cfloop>
								</div>
							</div>
							
						</cfloop>
						
					</div>
				</cfloop>

				<div id="Create" class="tabContent">
					
					<form id="formCreate" onSubmit="javascript:return processVerfiyForm('formCreate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('schemaCreateDo')#</cfoutput>">
						
						<div class="label">
							<b>执行专业</b>
							<select name="InstituteID" id="InstituteID" class="inlinePart">
                                <cfloop query="rs_ins">
									<option value="<cfoutput>#rs_ins.institute_id#</cfoutput>"><cfoutput>#rs_ins.institute_name#</cfoutput></option>
								</cfloop>
							</select>
							<select name="SubjectID" id="SubjectID" class="inlinePart"></select>
							
							<cfset i = 0 />

							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								$(document).ready(function() {
									
									var subArray = [
										<cfloop query="rs_sub">
										<cfset i++ />
										['<cfoutput>#rs_sub.sbj_id#</cfoutput>','<cfoutput>#rs_sub.sbj_name#</cfoutput>','<cfoutput>#rs_sub.institute_id#</cfoutput>']<cfif i lt rs_sub.recordCount>,</cfif>
										</cfloop>
									];
									
									function inputFlush(inputID, dataArray, parentID) {
									
										$("#" + inputID).removeOption(/./);
										for (var i = 0; i < dataArray.length; i++) {
											if (subArray[i][2] == parentID) {
												$("#" + inputID).addOption(dataArray[i][0], dataArray[i][1]);
											}
										}
										$("#" + inputID).val($("#" + inputID + " option:first").attr('value'));
									}
									
									/* init SELECTs */
									inputFlush("SubjectID", subArray, "<cfoutput>#rs_ins['institute_id'][1]#</cfoutput>");
									
									$("#InstituteID").change(function(){
										inputFlush("SubjectID", subArray, $(this).val());
									});
									
								});
								// -->
								//]]>				
							</script>
						</div>
						
						<div class="label">
							<b>培养方案版本</b>
							<select name="Grade">
								<cfloop from="#(year(now())-10)#" to="#(year(now())+1)#" index="grade">
								<option <cfif grade eq year(now())>selected="selected"</cfif> value="<cfoutput>#grade#</cfoutput>"><cfoutput>#grade#</cfoutput></option>
								</cfloop>
							</select>
						</div>
						
						<hr/>

						<div class="label">
							<b>毕业总学分</b>
							<input name="Credit" id="Credit" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('Credit', 0)#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>学分子项要求</b>
							必修课<input name="CreditRequired" id="CreditRequired" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditRequired', 0)#</cfoutput>" />
							选修课<input name="CreditOptional" id="CreditOptional" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditOptional', 0)#</cfoutput>" />
							素质拓展类<input name="CreditRelish" id="CreditRelish" type="text" class="typeSmallInt" verification="double" maxlength="6" value="<cfoutput>#event.getArg('CreditRelish', 0)#</cfoutput>" />
							<p class="notice">此处的各项学分用于毕业资格审核, 如果对于某一个子项不做要求, 请将学分值设置为0</p>
						</div>
						
						<hr/>
						
						<div class="label">
							<b>毕业总学时</b>
							<input name="Period" id="Period" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('Period', 0)#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>学时子项要求</b>
							必修课<input name="PeriodRequired" id="PeriodRequired" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('PeriodRequired', 0)#</cfoutput>" />
							选修课<input name="PeriodOptional" id="PeriodOptional" type="text" class="typeSmallInt" verification="integer" maxlength="8" value="<cfoutput>#event.getArg('PeriodOptional', 0)#</cfoutput>" />
							<p class="notice">此处的各项学时要求用于毕业资格审核的学时数补充, 如果对于某一个子项不做要求, 请将值设置为0</p>
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="制定培养方案" />
							<input class="button" type="reset" value="重设表格" />
						</div>
						
					</form>
					
				</div>
				
				<div id="Copy" class="tabContent">
					
					<form id="formCopy" onSubmit="javascript:return formCheck('formCopy');" class="formWrapper" method="post" action="<cfoutput>#buildURL('schemaCopyDo')#</cfoutput>">
						
						<div class="label">
							<b>学院</b>
							<select name="TargetInstituteID" id="TargetInstituteID" class="inlinePart">
                                <cfloop query="rs_sourceDep">
									<option value="<cfoutput>#rs_sourceDep.institute_id#</cfoutput>"><cfoutput>#rs_sourceDep.institute_name#</cfoutput></option>
								</cfloop>
							</select>
						</div>
						
						<div class="label">
							<b>复制内容</b>

							<select name="srcGrade" id="srcGrade" class="inlinePart">
								<cfloop from="#(year(now())-10)#" to="#(year(now())+1)#" index="grade">
								<option <cfif grade eq (year(now()) -1)>selected="selected"</cfif> value="<cfoutput>#grade#</cfoutput>"><cfoutput>#grade#</cfoutput></option>
								</cfloop>
							</select>
							版 复制到 
							<select name="targetGrade" id="targetGrade" class="inlinePart">
								<cfloop from="#(year(now())-10)#" to="#(year(now())+1)#" index="grade">
								<option <cfif grade eq year(now())>selected="selected"</cfif> value="<cfoutput>#grade#</cfoutput>"><cfoutput>#grade#</cfoutput></option>
								</cfloop>
							</select>
							级
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button1" type="submit" value="开始复制培养方案" />
							<input class="button" type="reset" value="重设表格" />
						</div>

					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function formCheck(formId) {
							
							var $form = $("#"+ formId);
							var $srcGrade = $("#srcGrade", $form).removeClass("typeError");
							var $tagGrade = $("#targetGrade", $form).removeClass("typeError");
							
							if ( $srcGrade.val() == $tagGrade.val() ) {
								$srcGrade.addClass("typeError");
								$tagGrade.addClass("typeError");
							}
							if ( $srcGrade.val() > $tagGrade.val() ) {
								$srcGrade.addClass("typeError");
							}

							if ( $srcGrade.val() < $tagGrade.val() ) {
								return true;
							}
														
							return false;
						}
						// -->
						//]]>
					</script>

				</div>

				<div id="Import" class="tabContent">
					
					<div class="noticeBlock">
						<h3>导入培养方案专业课程开设数据</h3>
						<p><span class="img icon16x16 message"></span>请严格按照如下的数据模板在电子表格文件中录入培养方案基础数据. 点击<a href="<cfoutput>#buildURL('importSchemaTemplate')#</cfoutput>">下载培养方案录入模板</a>, 在录入信息时请勿更改第一行表头内容.</p>
						<hr/>
						<table>
							<tr>										
								<td>专业</td><td>年级</td><td>课程号</td><td>课程</td><td>是否必修</td><td>课程类别</td><td>开课学期</td><td>任课单位</td>
							</tr>
							<tr>
								<td>专业全称</td><td>2012</td><td>201209011</td><td>大学外语[A3]</td><td>必修 / 限选</td><td>公共课 / 专业课 / 实践课 / 实验课</td><td>3</td><td>开课学院部门全称</td>
							</tr>
						</table>
						<p>可选填信息</p>
						<hr/>
						<table>
							<tr>
								<td>学位课</td><td>双学位</td><td>辅修</td>
							</tr>
							<tr>
								<td>是 / 否</td><td>是 / 否</td><td>是 / 否</td>
							</tr>
						</table>
						<hr/>
					</div>
					
					<form target="output" onSubmit="javascript:return processVerfiyForm('formImport');" id="formImport" class="formWrapper" method="post" enctype="multipart/form-data" action="<cfoutput>#buildURL('importSchemaDo')#</cfoutput>">
						
						<div class="label">
							<span class="req">*</span><b>导入数据文件</b>
							<input name="upload" id="upload" type="file" verification="required" />
						</div>
						
						<div class="lable"><input id="importTrigger" class="button" type="submit" value="导入培养方案数据" /></div>
					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							$("#importTrigger").click(function(){
								$("#output").attr("src","about:blank").removeClass("hidden_elem");
							});
						});
						// -->
						//]]>
					</script>
					
					
					<iframe name="output" id="output" class="UIframeBox hidden_elem" src="about:blank" frameborder="0"></iframe>
					
				</div>
				
				<cfif rs_sign.recordCount>
					
					<div id="Waiting" class="tabContent">
						
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton" href="<cfoutput>#buildURL('schemaModifyBatchApproveDo')#</cfoutput>"><i class="mrs img btnExecute"></i><span class="uiButtonText">批量审批</span></a>
							</div>
							<h3>培养方案修订申请</h3>
							<hr/>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="60">申请人</td>
									<td width="140">对象</td>
									<td>修订原因</td>
									<td width="60">审批进程</td>
									<td width="70">申请时间</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_sign">
									<cfset row ++ />
									<cfset structInsert(passArgs, "REQ", rs_sign.sign_id, true) />
									
									<tr class="editRows <cfif event.getArg('REQ') eq rs_sign.sign_id> lastEdited</cfif>">
										<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
										<td><cfoutput>#rs_sign.tch_name#</cfoutput></td>
										<td><cfoutput>#rs_sign.sbj_name#</cfoutput> <span class="numeric"><cfoutput>#rs_sign.grade#</cfoutput></span>版</td>
										<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_sign.sign_reason )#</cfoutput></td>
										<td><cfoutput>#dictAdvice.getProgressStatus( rs_sign.sign_status )#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDateString( rs_sign.date_created, "YYYY/MM/DD" )#</cfoutput></span></td>
										<td><a class="stat config" href="<cfoutput>#buildURL('schemaModifyReview', passArgs)#</cfoutput>"></a></td>
									</tr>
																		
								</cfloop>
							</tbody>
						</table>
						
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>
